package core.communication.message;

import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;

import com.google.common.collect.Lists;

public class MessagePriorityQueue {
	private PriorityQueue<Message> priorityQueue = new PriorityQueue<Message>(1, new Comparator<Message>() {
		public int compare(Message o1, Message o2) {
			return (int) o2.getPriority().ordinal() - (int) o1.getPriority().ordinal();
		}
	});

	public Message get() {
		return priorityQueue.peek();
	}

	public void add(Message message) {
		priorityQueue.add(message);
	}

	public void remove(Message message) {
		List<Message> messages = Lists.newLinkedList(priorityQueue);
		messages.remove(message);
		priorityQueue.clear();
		priorityQueue.addAll(messages);
	}
}
